//
//  SiteListViewController.m
//  EasyToo
//
//  Created by Jr Lan on 13-9-2.
//
//

#import "SiteListViewController.h"
#import "BuySiteTicketViewController.h"
#import "DeviceUtil.h"

@interface SiteListViewController ()

@end

@implementation SiteListViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return [self.siteTicketInfo count] + 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
    }
    
    // Configure the cell...
    NSInteger width = [DeviceUtil getScreenWidth];
    if (indexPath.section ==  0 && indexPath.row ==  0) {
        //加载标题
        UILabel *titlelbl = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, width, 60)]autorelease];
        titlelbl.text = self.allSiteInfo.sceneName;
        titlelbl.font = [UIFont systemFontOfSize:20];
        titlelbl.textColor = [UIColor redColor];
        titlelbl.adjustsFontSizeToFitWidth = YES;
        titlelbl.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:titlelbl];
    } else {
        SiteTicketInfo *ticketInfo = [self.siteTicketInfo objectAtIndex:indexPath.row];
        //加载介绍
        UILabel *desclbl = [[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 180, 60)]autorelease];
        desclbl.text = ticketInfo.sceneTicketName;
        desclbl.font = [UIFont systemFontOfSize:20];
        desclbl.adjustsFontSizeToFitWidth = YES;
        desclbl.lineBreakMode = UILineBreakModeWordWrap;
        desclbl.numberOfLines = 0;
        [cell.contentView addSubview:desclbl];
        
        //价格
        UILabel *pricelbl = [[[UILabel alloc]initWithFrame:CGRectMake(210, 0, 100, 30)]autorelease];
        pricelbl.text = [NSString stringWithFormat:@"￥%@", ticketInfo.salePrice];
        pricelbl.font = [UIFont systemFontOfSize:20];
        pricelbl.textColor = [UIColor redColor];
        pricelbl.adjustsFontSizeToFitWidth = YES;
        [cell.contentView addSubview:pricelbl];
        
        //市场价格
        UILabel *compricelbl = [[[UILabel alloc]initWithFrame:CGRectMake(210, 40, 100, 20)]autorelease];
        compricelbl.text = [NSString stringWithFormat:@"市场价：￥%@", ticketInfo.agentPrice];
        compricelbl.font = [UIFont systemFontOfSize:15];
        compricelbl.adjustsFontSizeToFitWidth = YES;
        [cell.contentView addSubview:compricelbl];
    }
    
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BuySiteTicketViewController *buyticketController = [[BuySiteTicketViewController alloc]init];
    buyticketController.siteTicketInfo = [self.siteTicketInfo objectAtIndex:indexPath.row];
    buyticketController.allSiteInfo = self.allSiteInfo;
    [self.navigationController pushViewController:buyticketController animated:YES];
    [buyticketController release];
}

@end
